package com.ruoyi.psi.base.unit.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.psi.base.unit.domain.BaseUnit;
import com.ruoyi.psi.base.unit.service.IBaseUnitService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 计量单位信息
 *
 * @author Drj 2021/6/28
 */
@RestController
@RequestMapping("/psi/base/unit")
@Api(value = "计量单位信息模块", tags = "计量单位信息接口")
public class BaseUnitController extends BaseController {
    @Autowired
    private IBaseUnitService baseUnitService;

    /**
     * 获取计量单位列表
     * @param baseUnit
     * @return
     */
    @ApiOperationSupport(includeParameters = {"BaseUnit.baseUnit", "BaseUnit.createTime", "BaseUnit.baseUnitId"})
    @ApiOperation(value = "获取产品类别列表",notes = "查询所有产品类别信息")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody BaseUnit baseUnit){
        startPage();
        List<BaseUnit> baseUnitList = baseUnitService.selectBaseUnitList(baseUnit);
        return getDataTable(baseUnitList);
    }

    /**
     * 导出计量单位
     * @param baseUnit
     * @return
     */
    @PostMapping("/export")
    public AjaxResult export(@RequestBody BaseUnit baseUnit)
    {
        List<BaseUnit> list = baseUnitService.selectBaseUnitList(baseUnit);
        ExcelUtil<BaseUnit> util = new ExcelUtil<BaseUnit>(BaseUnit.class);
        return util.exportExcel(list, "计量单位数据");
    }

    /**
     * 新增计量单位
     * @param baseUnit
     * @return
     */
    @ApiOperation(value = "新增计量单位", notes = "新增计量单位")
    @ApiImplicitParam(name = "baseUnit", value = "新增计量单位", dataType = "BaseUnit")
    @PostMapping("/add")
    public AjaxResult add(@Validated @RequestBody BaseUnit baseUnit){

        return toAjax(baseUnitService.insertBaseUnit(baseUnit));
    }

    /**
     * 修改计量单位
     * @param baseUnit
     * @return
     */
    @ApiOperation(value = "修改计量单位", notes = "修改计量单位")
    @ApiImplicitParam(name = "baseUnit", value = "修改计量单位", dataType = "BaseUnit")
    @PostMapping("/edit")
    public AjaxResult edit(@Validated @RequestBody BaseUnit baseUnit)
    {
        return toAjax(baseUnitService.updateBaseUnit(baseUnit));
    }

    /**
     * 删除计量单位
     * 仅修改删除标志位
     * @param baseUnit
     * @return
     */
    @PostMapping("/delete")
    public AjaxResult delete(@RequestBody BaseUnit baseUnit)
    {

        return toAjax(baseUnitService.updateBaseUnitDeleteFlag(baseUnit));
    }
}
